home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Interfaces / CIncludes / OpenTptInternet.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-13  |  10.1 KB  |  378 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        OpenTptInternet.h
  3.  
  4.     Contains:    Client TCP/IP definitions
  5.  
  6.     Copyright:    © 1993-1995 by Apple Computer, Inc., all rights reserved.
  7.  
  8.  
  9. */
  10.  
  11.  
  12. #ifndef __OPENTPTINTERNET__
  13. #define __OPENTPTINTERNET__
  14.  
  15. #ifndef REZ
  16.     #ifndef __OPENTRANSPORT__
  17.     #include <OpenTransport.h>
  18.     #endif    
  19.     #if PRAGMA_ALIGN_SUPPORTED
  20.     #pragma options align=mac68k
  21.     #endif
  22.  
  23. /*******************************************************************************
  24. ** Misc 
  25. ********************************************************************************/
  26.  
  27. typedef UInt16    InetPort;
  28. typedef UInt32    InetHost;
  29.  
  30. //
  31. //    Enums used as address type designations.
  32. //
  33. enum
  34. {
  35.     AF_INET                = 2,    // Traditonal
  36.     AF_DNS                = 42    // Obviously, the answer to...
  37. };
  38.  
  39. //
  40. //    Enum which can be used to bind to all IP interfaces
  41. //    rather than a specific one.
  42. //
  43. enum
  44. {
  45.     kOTAnyInetAddress    = 0        // Wildcard
  46. };
  47.  
  48. #ifdef __cplusplus
  49.     class    TInternetServices;
  50.     typedef TInternetServices*    InetSvcRef;
  51. #else
  52.     typedef void*    InetSvcRef;
  53. #endif
  54.  
  55.  
  56. #endif    /*    REZ    */
  57.  
  58. /*******************************************************************************
  59. ** Some prefixes for shared libraries
  60. ********************************************************************************/
  61.  
  62. #define kInetVersion    "3.0"                /* MacTCP 3.0 */
  63. #define kInetPrefix        "ot:inet$"
  64.  
  65. /*******************************************************************************
  66. ** Module Names
  67. ********************************************************************************/
  68. #define kDNRName        "dnr"
  69. #define kTCPName        "tcp"
  70. #define kUDPName        "udp"
  71. #define kRawIPName        "rawip"
  72.  
  73. /*******************************************************************************
  74. ** XTI Options
  75. ********************************************************************************/
  76.  
  77. // Protocol levels
  78.  
  79. #define    INET_IP         0x0
  80. #define    INET_TCP     0x06
  81. #define    INET_UDP     0x11
  82.  
  83.  
  84. // TCP Level Options
  85.  
  86. #define    TCP_NODELAY                     0x01
  87. #define    TCP_MAXSEG                     0x02
  88. #define TCP_NOTIFY_THRESHOLD        0x10    /** not a real XTI option */
  89. #define TCP_ABORT_THRESHOLD            0x11    /** not a real XTI option */
  90. #define TCP_CONN_NOTIFY_THRESHOLD    0x12    /** not a real XTI option */
  91. #define TCP_CONN_ABORT_THRESHOLD    0x13    /** not a real XTI option */
  92. #define TCP_OOBINLINE                0x14    /** not a real XTI option */
  93. #define TCP_URGENT_PTR_TYPE            0x15    /** not a real XTI option */
  94. #define    TCP_KEEPALIVE                 OPT_KEEPALIVE    /* keepalive defined in OpenTransport.h */
  95.  
  96. #define    T_GARBAGE                     2            
  97.  
  98.  
  99. // UDP Level Options
  100.  
  101. #define    UDP_CHECKSUM        OPT_CHECKSUM
  102. #define UDP_RX_ICMP            0x2
  103.  
  104. // IP Level Options
  105.  
  106. #define    IP_OPTIONS             0x01
  107. #define    IP_TOS                 0x02
  108. #define    IP_TTL                 0x03
  109. #define    IP_REUSEADDR         0x04
  110. #define    IP_DONTROUTE         0x10
  111. #define    IP_BROADCAST         0x20
  112. #define    IP_HDRINCL             0x1002    
  113. #define IP_RCVOPTS             0x1005
  114. #define IP_RCVDSTADDR         0x1007
  115. #define    IP_MULTICAST_IF         0x1010        /* set/get IP multicast interface    */
  116. #define    IP_MULTICAST_TTL     0x1011        /* set/get IP multicast timetolive    */
  117. #define    IP_MULTICAST_LOOP     0x1012        /* set/get IP multicast loopback    */
  118. #define    IP_ADD_MEMBERSHIP     0x1013        /* add an IP group membership        */
  119. #define    IP_DROP_MEMBERSHIP     0x1014        /* drop an IP group membership        */
  120. #define    IP_BROADCAST_IF         0x1015        /* Set interface for broadcasts     */
  121. #define    IP_RCVIFADDR         0x1016        /* Set interface for broadcasts     */
  122.  
  123. //    DVMRP-specific setsockopt commands, from ip_mroute.h
  124. //
  125. #define    DVMRP_INIT        100
  126. #define    DVMRP_DONE        101
  127. #define    DVMRP_ADD_VIF    102
  128. #define    DVMRP_DEL_VIF    103
  129. #define    DVMRP_ADD_LGRP    104
  130. #define    DVMRP_DEL_LGRP    105
  131. #define    DVMRP_ADD_MRT    106
  132. #define    DVMRP_DEL_MRT    107
  133.  
  134.  
  135. #ifndef REZ
  136.  
  137. // IP_TOS precdence levels
  138. enum
  139. {
  140.     T_ROUTINE        = 0,
  141.     T_PRIORITY        = 1,
  142.     T_IMMEDIATE        = 2,
  143.     T_FLASH            = 3,
  144.     T_OVERRIDEFLASH    = 4,
  145.     T_CRITIC_ECP    = 5,
  146.     T_INETCONTROL    = 6,
  147.     T_NETCONTROL    = 7
  148. };
  149.  
  150. //    IP_TOS type of service
  151. enum
  152. {
  153.     T_NOTOS        = 0x0,        
  154.     T_LDELAY    = (1<<4),
  155.     T_HITHRPT    = (1<<3),
  156.     T_HIREL     = (1<<2)
  157. };
  158.  
  159. #define    SET_TOS(prec,tos)    (((0x7 & (prec)) << 5) | (0x1c & (tos)))
  160.  
  161. // IP Multicast option structures
  162. struct TIPAddMulticast
  163. {
  164.     InetHost multicastGroupAddress;
  165.     InetHost interfaceAddress;
  166. };
  167. typedef struct TIPAddMulticast TIPAddMulticast;
  168.  
  169.  
  170. /*******************************************************************************
  171. ** Protocol-specific events
  172. ********************************************************************************/
  173.  
  174. enum
  175. {
  176.     T_DNRSTRINGTOADDRCOMPLETE    = kPRIVATEEVENT+1,
  177.     T_DNRADDRTONAMECOMPLETE        = kPRIVATEEVENT+2,
  178.     T_DNRSYSINFOCOMPLETE        = kPRIVATEEVENT+3,
  179.     T_DNRMAILEXCHANGECOMPLETE    = kPRIVATEEVENT+4,
  180.     T_DNRQUERYCOMPLETE            = kPRIVATEEVENT+5
  181. };
  182.  
  183. /*******************************************************************************
  184. ** InetAddress
  185. ********************************************************************************/
  186.  
  187. struct InetAddress
  188. {
  189.         OTAddressType    fAddressType;    // always AF_INET
  190.         InetPort        fPort;            // Port number 
  191.         InetHost        fHost;            // Host address in net byte order
  192.         UInt8            fUnused[8];        // Traditional unused bytes
  193. };
  194. typedef struct InetAddress InetAddress;
  195.  
  196. /*******************************************************************************
  197. ** Domain Name Resolver (DNR) 
  198. ********************************************************************************/
  199.  
  200. enum 
  201.         kMaxHostAddrs         =  10,
  202.         kMaxSysStringLen     =  32,
  203.         kMaxHostNameLen        = 255
  204. };
  205.  
  206. typedef char InetDomainName[kMaxHostNameLen + 1];
  207.  
  208. struct InetHostInfo
  209. {
  210.     InetDomainName    name;
  211.     InetHost        addrs[kMaxHostAddrs];
  212. };
  213. typedef struct InetHostInfo    InetHostInfo;
  214.  
  215. struct InetSysInfo
  216. {
  217.     char        cpuType[kMaxSysStringLen];
  218.     char        osType[kMaxSysStringLen];
  219. };
  220. typedef struct InetSysInfo InetSysInfo;
  221.  
  222. struct InetMailExchange
  223. {
  224.     UInt16            preference;
  225.     InetDomainName    exchange;
  226. };
  227. typedef struct InetMailExchange InetMailExchange;
  228.  
  229. struct DNSQueryInfo
  230. {
  231.     UInt16            qType;
  232.     UInt16            qClass;
  233.     UInt32            ttl;
  234.     InetDomainName    name;
  235.     UInt16            responseType;        // answer, authority, or additional
  236.     UInt16            resourceLen;        // actual length of array which follows
  237.     char            resourceData[4];    // size varies
  238. };
  239. typedef struct DNSQueryInfo DNSQueryInfo;
  240.  
  241.  
  242. /*******************************************************************************
  243. ** DNSAddress
  244. **
  245. **        The DNSAddress format is optional and may be used in connects,
  246. **        datagram sends, and resolve address calls.   The name takes the 
  247. **        format "somewhere.com" or "somewhere.com:portnumber" where
  248. **        the ":portnumber" is optional.   The length of this structure
  249. **        is arbitrarily limited to the overall max length of a domain
  250. **        name (255 chars), although a longer one can be use successfully
  251. **        if you use this as a template for doing so.   However, the domain name 
  252. **        is still limited to 255 characters.
  253. ********************************************************************************/
  254.  
  255. struct DNSAddress
  256. {
  257.     OTAddressType    fAddressType;    // always AF_DNS
  258.     InetDomainName    fName;            
  259. };
  260. typedef struct DNSAddress DNSAddress;
  261.  
  262. /*******************************************************************************
  263. ** InetInterfaceInfo
  264. ********************************************************************************/
  265.  
  266. struct InetInterfaceInfo
  267. {
  268.     InetHost        fAddress;
  269.     InetHost        fNetmask;
  270.     InetHost        fBroadcastAddr;
  271.     InetHost        fDefaultGatewayAddr;
  272.     InetHost        fDNSAddr;
  273.     UInt16            fVersion;
  274.     UInt16            fHWAddrLen;
  275.     UInt8*            fHWAddr;
  276.     UInt32            fIfMTU;
  277.     UInt8*            fReservedPtrs[2];
  278.     InetDomainName    fDomainName;
  279.     UInt8            fReserved[256];            
  280. };
  281. typedef struct InetInterfaceInfo InetInterfaceInfo;
  282.  
  283.  
  284.  
  285. /*******************************************************************************
  286. ** Static helper functions
  287. ********************************************************************************/
  288.  
  289. #ifdef __cplusplus
  290. extern "C" {
  291. #endif
  292.  
  293. extern pascal void             OTInitInetAddress(InetAddress* addr, InetPort port, InetHost host);
  294. extern pascal size_t        OTInitDNSAddress(DNSAddress* addr, char* str);
  295. extern pascal OSStatus         OTInetStringToHost(char* str, InetHost* host);
  296. extern pascal void          OTInetHostToString(InetHost host, char* str);
  297. extern pascal OSStatus         OTInetGetInterfaceInfo(InetInterfaceInfo* info, SInt32 val);
  298.  
  299. #ifdef __cplusplus
  300. }
  301. #endif
  302.  
  303.  
  304. /*******************************************************************************
  305. ** InetServices & DNR calls
  306. ********************************************************************************/
  307.  
  308. #define kDefaultInternetServicesPath    ((OTConfiguration*)-3)
  309.  
  310. #if !OTKERNEL
  311.  
  312. #ifdef __cplusplus
  313. extern "C" {
  314. #endif
  315.  
  316. extern pascal InetSvcRef     OTOpenInternetServices(OTConfiguration* cfig, OTOpenFlags oflag, OSStatus* err);
  317. extern pascal OSStatus        OTAsyncOpenInternetServices(OTConfiguration* cfig, OTOpenFlags oflag, 
  318.                                                         OTNotifyProcPtr proc, void* contextPtr);
  319. extern pascal OSStatus         OTInetStringToAddress(InetSvcRef ref, char* name,
  320.                                                   InetHostInfo* hinfo);
  321. extern pascal OSStatus         OTInetAddressToName(InetSvcRef ref, InetHost addr, 
  322.                                                 InetDomainName name);
  323. extern pascal OSStatus         OTInetSysInfo(InetSvcRef ref, char* name,
  324.                                           InetSysInfo* sysinfo);
  325. extern pascal OSStatus         OTInetMailExchange(InetSvcRef ref, char* name, UInt16* num,
  326.                                                InetMailExchange* mx);
  327.                                                
  328. extern pascal OSStatus        OTInetQuery(InetSvcRef ref, char* name, UInt16 qClass, UInt16 qType,
  329.                                           char* buf, size_t buflen, 
  330.                                         void** argv, size_t argvlen,
  331.                                         OTFlags flags);
  332.                     
  333.  
  334. #ifdef __cplusplus
  335. }
  336. #endif
  337.  
  338. enum
  339. {
  340.     kDefaultInetInterface    = -1,
  341.     kInetInterfaceInfoVersion    = 2
  342. };
  343.  
  344. #ifdef __cplusplus
  345.  
  346. class TInternetServices : public TProvider
  347. {
  348.     public:
  349.             OSStatus     StringToAddress(char* name, InetHostInfo* hinfo)
  350.                         { return OTInetStringToAddress(this, name, hinfo); }
  351.                     
  352.             OSStatus     AddressToName(InetHost addr, InetDomainName name)
  353.                         { return OTInetAddressToName(this, addr, name); }
  354.                     
  355.             OSStatus     SysInfo(char* name, InetSysInfo* sysinfo )
  356.                         { return OTInetSysInfo(this, name, sysinfo); }
  357.                     
  358.             OSStatus     MailExchange(char* name, UInt16* num, InetMailExchange* mx)
  359.                         { return OTInetMailExchange(this, name, num, mx); }
  360.                         
  361.             OSStatus    Query(char* name, UInt16 qClass, UInt16 qType, 
  362.                               char* buf, size_t buflen, 
  363.                               void** argv, size_t argvlen,
  364.                               OTFlags flags)
  365.                         { return OTInetQuery(this, name, qClass, qType, buf, buflen, argv, argvlen, flags); }
  366. };
  367.  
  368. #endif
  369. #endif        /* !OTKERNEL */
  370.  
  371. #if PRAGMA_ALIGN_SUPPORTED
  372. #pragma options align=reset
  373. #endif
  374.  
  375. #endif    /*    REZ    */
  376. #endif        /* __OTINTERNET__ */
  377.